import { del, get, post } from "@/utils/request";

export interface Pet {
    id: number,     // 宠物id
    user_id: number, // 用户id
    name: string, // 宠物名称
    type: number, // 宠物类型
    typeString: string, // 宠物类型字符串
    breed: number, // 宠物品种
    breedString: string, // 宠物品种字符串
    gender: number, // 性别
    birthday: string, // 生日
    adoption_date: string, // 领养日期
    avatar: string, // 宠物头像
    remark: string, // 宠物描述
}

export interface PetType {
    id: number,
    name: string,
}

export interface PetBreed {
    id: number,
    pet_type_id: number,
    name: string,
}

export function emptyPet() {
    return {
    id: 0,
    user_id: 0,
    name: "",
    type: 1,
    typeString: "",
    breed: 1,
    breedString: "",
    gender: 1,
    birthday: new Date().toISOString().slice(0, 10),
    adoption_date: "",
    avatar: "",
    remark: ""
  };
}

export interface PageInfo<T> {
  total: number;
  pageNum: number;
  pageSize: number;
  list: T[];
}

export function listPets( data: { pageNum: number, pageSize: number }) {
  return get<PageInfo<Pet>>('/api/pet/list', data);
}

export function petTypeList() {
  return get<PetType[]>('/api/pet/list/type');
}

export function petBreedList( data: { petTypeId: number }) {
  return get<PetBreed[]>('/api/pet/list/breed', data);
}

export function addPet(pet: Pet) {
  return post<null>('/api/pet/add', pet);
}

export function delPet(id: number) {
  return del<null>(`/api/pet/del/${id}`);
}

export function searchPetNameToServer(data: { pageNum: number, pageSize: number, name: string }) {
    return get<PageInfo<Pet>>('/api/pet/search', data);
}

export function searchPetById(id: number) {
    return get<Pet>(`/api/pet/info/${id}`);
}